import { Vector2 } from "../vector";  
import { Engine } from "../engine";  
import { CameraEffect } from "./camera-effect";  
import { lerp } from "../utils";  
  
export class CharacterZoomEffect extends CameraEffect {  
  private startZoom: number = 1;  
  private targetZoom: number;  
  
  constructor(engine: Engine, targetZoom: number = 1.5) {  
    super(engine);  
    this.targetZoom = targetZoom;  
  }  
  
  start(duration: number = 2000): void {  
    super.start(duration);  
    this.startZoom = this.engine.camera.getZoom();  
  }  
  
  apply(basePos: Vector2): Vector2 {  
    if (!this.isActive) return basePos;  
  
    // 计算当前缩放级别  
    const currentZoom = lerp(this.startZoom, this.targetZoom, this.progress);  
      
    // 直接设置相机的缩放属性  
    this.engine.camera.setZoom(currentZoom);  
  
    // 获取角色位置  
    const playerPos = this.engine.player.body_.pos;  
    const canvas = this.engine.canvas_;  
  
    // 计算以角色为中心的相机位置  
    const centeringPos = new Vector2(  
      lerp(basePos.x, playerPos.x - canvas.width / 2, this.progress * 0.8),  
      lerp(basePos.y, playerPos.y - canvas.height / 2, this.progress * 0.8)  
    );  
  
    return centeringPos;  
  }  
  
  getCurrentZoom(): number {  
    return this.engine.camera.getZoom();  
  }  
}